from datetime import datetime

from exts import db


class BaseModel(db.Model):
    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    create_time = db.Column(db.DateTime, default=datetime.now)

    def save(self):
        try:
            db.session.add(self)
            db.session.commit()
            return True
        except Exception as err:
            print(err)
            return False

    def delete(self):
        try:
            db.session.delete(self)
            db.session.commit()
            return True
        except Exception as err:
            print(err)
            return False
